package br.com.easyrhour3x.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@Table(name = "usuario_has_solicitacao")
@AssociationOverrides({
		@AssociationOverride(name = "id.solicitacao", joinColumns = @JoinColumn(name = "id_solicitacao")),
		@AssociationOverride(name = "id.usuario", joinColumns = @JoinColumn(name = "id_usuario")) })
@NamedQuery(name = "UsuarioHasSolicitacao.finalizarAtendimento", query = "update UsuarioHasSolicitacao s set "
   + "s.dataFim = :dataFimParam where s.id.solicitacao = :idSolicitacaoParam and s.id.usuario = :idUsuarioParam")
public class UsuarioHasSolicitacao implements Serializable {
	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private UsuarioHasSolicitacaoPK id = new UsuarioHasSolicitacaoPK();

	@Temporal(TemporalType.TIMESTAMP)
	private Date dataFim;

	@Temporal(TemporalType.TIMESTAMP)
	private Date dataInicio;

	public UsuarioHasSolicitacao() {
	}

	@EmbeddedId
	public UsuarioHasSolicitacaoPK getId() {
		return this.id;
	}

	public void setId(UsuarioHasSolicitacaoPK id) {
		this.id = id;
	}

	public Date getDataFim() {
		return this.dataFim;
	}

	public void setDataFim(Date dataFim) {
		this.dataFim = dataFim;
	}

	public Date getDataInicio() {
		return this.dataInicio;
	}

	public void setDataInicio(Date dataInicio) {
		this.dataInicio = dataInicio;
	}

	@Transient
	public Solicitacao getSolicitacao() {
		return id.getSolicitacao();
	}

	public void setSolicitacao(Solicitacao solicitacao) {
		id.setSolicitacao(solicitacao);
	}

	@Transient
	public Usuario getUsuario() {
		return id.getUsuario();
	}

	public void setUsuario(Usuario usuario) {
		id.setUsuario(usuario);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((dataFim == null) ? 0 : dataFim.hashCode());
		result = prime * result + ((dataInicio == null) ? 0 : dataInicio.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UsuarioHasSolicitacao other = (UsuarioHasSolicitacao) obj;
		if (dataFim == null) {
			if (other.dataFim != null)
				return false;
		} else if (!dataFim.equals(other.dataFim))
			return false;
		if (dataInicio == null) {
			if (other.dataInicio != null)
				return false;
		} else if (!dataInicio.equals(other.dataInicio))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}